package com.zjw.dao.impl;

import com.zjw.dao.BaseDao;
import com.zjw.entity.Admin;
import com.zjw.dao.AdminDao;
import com.zjw.utils.ConnectionUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 管理员信息表(Admin)表数据库访问层实现类
 *
 * @author 翟
 * @since 2025-04-09 09:21:58
 */
public class AdminDaoImpl extends BaseDao implements AdminDao {

    public AdminDaoImpl(Connection connection) {
        super(connection);
    }

    @Override
    public Admin selectAdminByUsernameAndPassword(Admin admin) throws SQLException {
        String sql = "select admin_id , admin_name , password from admin where admin_name = ? and password = ?";
        ResultSet resultSet = null;
        try {
            resultSet = executeQuery(sql , admin.getAdminName() , admin.getPassword());
            if (resultSet.next()){
                Admin admin1 = new Admin();
                admin1.setAdminId(resultSet.getInt("admin_id"));
                admin1.setAdminName(resultSet.getString("admin_name"));
                admin1.setPassword(resultSet.getString("password"));
                return admin1;
            }
        } finally {
            ConnectionUtil.closeALL(resultSet , null , null);
        }
        return null;
    }
}
